<?php
declare (strict_types = 1);

namespace app\index\model;


/**
 * @mixin think\Model
 */
class Tag extends \app\common\model\content\Tag
{
    const LIMIT_NUM = 200;


    //获取查询构造器
    private static function getQuery(array $where){
        return static::where($where);
    }


    //获取指定条件下标签数目
    public static function getCount(array $where = []){
        return static::getQuery($where)->count();
    }

    //获取标签列表
    public static function getList($page, $limit, array $where){
        return static::getQuery($where)
            ->field(['id','name'])
            ->order('id', 'desc')
            ->paginate([
                'list_rows' => empty($limit) || $limit < 1 || $limit > 50 ? static::LIMIT_NUM : $limit,
                'page'      => empty($page) || $page <= 0 ? 1 : $page,
            ])->each(function($item, $key){
                $item->url = (string) url('tag/read',['id'=>$item->id]);
            })->toArray();
    }

}
